package cn.brondfish.icedfish;

import android.content.Context;
import android.util.Log;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.Base64;

import javax.crypto.Cipher;

import cn.brondfish.icedfish.framework.util.BF_DeviceUniqueID;
import cn.brondfish.icedfish.framework.util.BF_SecretUtil;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
        assertEquals("cn.brondfish.icedfish", appContext.getPackageName());
        try {
            String id = BF_DeviceUniqueID.generateUniqueID(appContext);
            Log.i("deviceId:",id);

            KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
            keyPairGenerator.initialize(2048);
            KeyPair keyPair = keyPairGenerator.generateKeyPair();
            String privateK = Base64.getEncoder().encodeToString(keyPair.getPrivate().getEncoded());
            String publicK = Base64.getEncoder().encodeToString(keyPair.getPublic().getEncoded());
            Log.e("privateK:",privateK);
            Log.e("privateK:",publicK);

        } catch (Exception e) {
            Log.e("ExampleInstrumentedTest.useAppContext:",e.getMessage());
        }
    }
}